<!-- $Id: goods_info.htm 17126 2010-04-23 10:30:26Z liuhui $ -->
{include file="pageheader2.htm"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

<div class="tab-div">
    <div id="tabbar-div">
      <p>
        <span class="tab-front" id="general-tab">基本信息</span>
        <span class="tab-back" id="mix-tab">商品管理</span>
        <span class="tab-back" id="serviceprice-tab" onclick="getStock()">发放管理</span>
      </p>
    </div>

    <div id="tabbody-div" >
      <form enctype="multipart/form-data" action="" method="post" name="theForm" >
        <table width="90%" id="general-table" align="center" >
          <tr>
            <td class="label">赠品名称：</td>
            <td><input type="text" name="name" value="{$info.name|escape}"></td>
          </tr>
          <tr>
            <td class="label">扩展标识：</td>
            <td>{$info.extension_code}</td>
          </tr>
          <!-- 市场售价 -->
          <tr>
            <td class="label">原价：</td>
            <td><input type="text" name="original_price" value="{$info.original_price}" size="20" />
            </td>
          </tr>
          <!-- 市场售价end -->
          <!-- 销售价 -->
          <tr>
            <td class="label">销售价：</td>
            <td><input type="text" name="price" value="{$info.price}" size="20"/></td>
          </tr>
          <!-- 销售价end -->
          <tr>
            <td class="label">赠送条件：</td>
            <td><input type="text" name="min_price" value="{$info.min_price}" size="20"/>———<input type="text" name="max_price" value="{$info.max_price}" size="20"/></td>
          </tr>
          <tr>
          <td class="label">有效时间：</td>
            <td><input type="datetime-local" name="start_time" value="{$info.start_time}" />———<input type="datetime-local" name="end_time" value="{$info.end_time}" /></td>
          </tr>





          <!-- 销售价 -->
          <tr>
            <td class="label">是否上架：</td>
            <td><input type="checkbox" name="is_sale" value="1" {if $info.is_sale}checked="checked"{/if} /> 选择上架后才能正常销售，下架仅仅只是不可新购，但原购物车还有效</td>
          </tr>
          <!-- 销售价end -->
          <!-- 销售价 -->
          <tr>
            <td class="label">是否回收：</td>
            <td><input type="checkbox" name="is_delete" value="1" {if $info.is_delete}checked="checked"{/if} /> 选择回收后将立即废除所有未完成购买的赠品</td>
          </tr>
          <!-- 销售价end -->
          <!-- 上传图片 -->
          <tr>
            <td class="label">显示图片：</td>
            <td>
              <input type="file" name="img" size="35" />
              {if $info.img}
                <a href="activity.php?act=show_image&img_url={$info.img}" target="_blank"><img src="images/yes.gif" border="0" /></a>
              {else}
                <img src="images/no.gif" />
              {/if}
            </td>
          </tr>
          <!-- 上传图片end -->
        </table>
        <!-- 商品管理 -->
        <table width="90%" id="mix-table" style="display:none" align="center">
        {if $form_act eq 'insert' OR $info.is_delete}
          <tr>
            <td colspan="3">
              <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
              <input type="text" name="keyword2" class="keyword2">
              <input type="button" value="搜索" onclick="searchGoods($('input.keyword2').val())" class="button">
              <script type="text/javascript">
$('input.keyword2').keydown(function(e){
  if(e.keyCode==13){
     searchGoods($('input.keyword2').val()); //处理事件
     return false;
  }
});
              </script>
            </td>
          </tr>
          <!-- 商品选择区 -->
          <tr>
            <th>可选商品</th>
            <th>操作</th>
            <th>该赠品所含商品</th>
          </tr>
          <tr>
            <td width="42%">
              <select name="source_select2" size="20" style="width:100%" onchange="sz2.priceObj.value = this.options[this.selectedIndex].id" ondblclick="addItem('add_goods')">
              </select>
            </td>
            <td align="center">
              <p>数量<br /><input name="num" type="text" size="6" value="1" /></p>
              <p><input type="button" value="添加" onclick="addItem('add_goods')" class="button" /></p>
              <p><input type="button" value="删除" onclick="dropItem('drop_goods')" class="button" /></p>
            </td>
            <td width="42%">
              <select name="target_select2" size="20" style="width:100%" ondblclick="dropItem('drop_goods')">
                {foreach from=$goods_list item=goods}
                <option value="{$goods.value}">{$goods.text}</option>
                {/foreach}
              </select>
            </td>
          </tr>
        {else}
          <tr>
            <td width="42%">
              <select name="target_select2" size="20" style="width:100%">
                {foreach from=$goods_list item=goods}
                <option value="{$goods.value}">{$goods.text}</option>
                {/foreach}
              </select>
            </td>
          </tr>
        {/if}
        </table>
        {insert_scripts files="validator.js,tab.js"}
        <script type="text/javascript">
          var parent_id = '{$info.parent_id}';
          /* 搜索商品 */
          function searchGoods(keyword)
          {
            $.ajax({url:'?act=get_goods_list&keyword='+keyword,dataType:'json',async:false,success:function(result){
              if(result.error){
                alert(result.message);
              }else{
                addopt($('select[name="source_select2"]'), result.content);
              }
            }});
          }
          function addItem(act){
            var sku = $('select[name="source_select2"] option:selected').val();
            var num = $('input[name="num"]').val();
            $.ajax({url:'?act='+act+'&sku='+sku+'&num='+num+'&parent_id='+parent_id,dataType:'json',async:false,success:function(result){
              if(result.error){
                alert(result.message);
              }else{
                addopt($('select[name="target_select2"]'), result.content);
              }
            }});
          }
          function dropItem(act){
            var id = $('select[name="target_select2"] option:selected').val();
            $.ajax({url:'?act='+act+'&id='+id+'&parent_id='+parent_id,dataType:'json',async:false,success:function(result){
              if(result.error){
                alert(result.message);
              }else{
                addopt($('select[name="target_select2"]'), result.content);
              }
            }});
          }
          function addopt(obj,opt){
            var html = '';
            if(opt){
              $.each(opt, function(i,val){
                html += ('<option value="'+val.value+'" id="'+val.value+'">'+val.text+'</option>');
              });
            }
            $(obj).html(html);
          }
        </script>
        <!-- 商品管理end -->
        <!-- 库存 -->
        <table width="90%" id="serviceprice-table"  align="center" style="display:none">
          <!-- {foreach from=$stockList item=item} -->
          <tr>
            <td class="label">
              <span class="area_name">{$item.area_name}</span>：
            </td>
            <td>
              可抢数量：<span class="valid_number">{$item.valid_number}</span>　
              购物车数量：<span class="cart_number">{$item.cart_number}</span>　
              总发放数量：<span class="total_number">{$item.total_number}</span>　
              可添加发放数量：<input type="text" class="number" value="0" disabled size="6">　
              {if !$info.is_delete && $form_act eq 'update'}
              发放：<input type="text" name="addNumber[]" class="addNumber" value="0" max="0" size="6">个　
              <input type="button" class="button" onclick="setStock($(this).parent().find('.addNumber').val(),$(this).parent().find('.number').val(),{$item.area_id})" value="点击发放">
              {/if}
            </td>
          </tr>
          <!-- {/foreach} -->
        </table>
        <script type="text/javascript">
          function getStock(){
            $.ajax({url:'?act=getStock&parent_id='+parent_id,dataType:'json',async:false,success:function(result){
              if(result.content){
                $.each(result.content, function(i,val){
                  $("#serviceprice-table tr").eq(i).find('.area_name').text(val.area_name);
                  $("#serviceprice-table tr").eq(i).find('.valid_number').text(val.valid_number);
                  $("#serviceprice-table tr").eq(i).find('.cart_number').text(val.cart_number);
                  $("#serviceprice-table tr").eq(i).find('.total_number').text(val.total_number);
                  $("#serviceprice-table tr").eq(i).find('.number').val(val.stock);
                  $("#serviceprice-table tr").eq(i).find('.addNumber').val(val.stock);
                });
              }
            }});
          }
          function setStock(num, stock, areaId){
            stock = parseInt(stock);
            num = parseInt(num);
            if(num > 0 && num <= stock && areaId > 0 && parent_id > 0){
              $.ajax({url:'?act=setStock&parent_id='+parent_id+'&num='+num+'&area_id='+areaId,dataType:'json',async:false,success:function(result){
                if(result.error > 0){
                  alert(result.message);
                }else{
                  getStock();
                }
              }});
            }
          }
        </script>
        <!-- 库存END -->

        <div class="button-div">
          <input type="hidden" name="parent_id" value="{$info.parent_id}" />
          <input type="submit" value="{$lang.button_submit}" class="button" />
          <input type="reset" value="{$lang.button_reset}" class="button" />
        </div>
        <input type="hidden" name="act" value="{$form_act}" />
      </form>
    </div>
</div>
<!-- end goods form -->
{insert_scripts files="validator.js,tab.js"}

{include file="pagefooter.htm"}
